package com.sky.controller.admin;

import com.sky.properties.MinioProperties;
import com.sky.result.Result;
import com.sky.utils.MinioUtilS;
import io.minio.MinioClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "通用功能接口")
@RestController
@RequestMapping("/admin/common")
@Slf4j
public class CommonController {
    @Autowired
    private MinioUtilS minioUtilS;

    /**
     * 文件上传
     *
     * @return 文件上传路径
     */
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) {
        log.info("开始文件上传:{}", file);
        List<String> upload = minioUtilS.upload(new MultipartFile[]{file});
        MinioProperties minioProperties = minioUtilS.getMinioProperties();
        String path = minioProperties.getEndpoint() + "/" + minioProperties.getBucketName() + "/" + upload.get(0);
        return Result.success(path);
    }
}
